$(document).ready(function () {
    var username = $("#top_user_login_tag").val();

    $.each($(".content ul li"), function () {
        var price = $(this).find(".productprice").val();
        var count = $(this).find(".productcount").val();
        $(this).find(".cartGoodsSum").val(count);
        $(this).find(".money").text(parseInt(count) * parseInt(price));
        AllPrice();
    });


    $.each($(".content .spinner button"), function () {
        $(this).click(function () {
            var price = $(this).parents(".content ul li").find(".productprice").val();
            var c = $(this).parents(".content ul li").find(".cartGoodsSum").val();
            $(this).parents(".content ul li").find(".money").text(parseInt(price) * parseInt(c));
            AllPrice();
        });

    });

    function AllPrice() {
        var sum = 0;
        $(".lineItem").each(function () {
            var money = $(this).find(".money").text();
            sum += parseInt(money);
        });
        $(".totalMoney").text("￥" + sum);
    }


    $("#submitButton").click(function () {
        var count = $(".goodul li").length;
        var totalmoney = $(".totalMoney").text();

        $.ajax({
            type: "POST",
            url: "/submitOrder",
            data: {
                count: count,
                totalmoney: totalmoney
            },
            cache: false,
            dataType: "text",
            success: function (data) {
                if ("成功" == data) {
                    window.location.href = "/userCenter/payMoney";
                } else {
                    alert("结算失败！");
                    window.location.reload();
                }
            }

        });
    });

});
